<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<link href="static/plugin/kangarooImgupload/css/imgupload.css" rel="stylesheet"/>
<script src="static/plugin/kangarooImgupload/js/imgupload.js"></script>

<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
        <span aria-hidden="true">&times;</span></button>
    <h4 class="modal-title">资质证书</h4>
</div>
<div class="modal-body">
    <div class="form-horizontal row">
        <form id="form_data">
            <div id="div_error" class="col-sm-12"></div>
            <input type="hidden" id="expertId" name="expertId" value="${data.expertId}">
            <input type="hidden" id="id" name="id" value="${data.id}">
            <div class="form-group col-sm-6 ">
                <label class="col-sm-4 control-label">证书类型：</label>
                <div class="col-sm-6">
                    <select class="form-control " id="certificateTypeId" name="certificateTypeId">
                        <option value="">&nbsp;</option>
                    </select>
                </div>
            </div>
            <div class="form-group col-sm-6 ">
                <label class="col-sm-4 control-label">专家类型：</label>
                <div class="col-sm-6">
                    <select class="form-control " id="grade" name="grade">
                        <option value="">&nbsp;</option>
                    </select>
                </div>
            </div>
            <div class="form-group col-sm-6 ">
                <label class="control-label col-sm-4 ">证书名称：</label>
                <div class="col-sm-6">
                    <input type="text" class="form-control"  name="name" value="${data.name}">
                </div>
            </div>
            <div class="form-group col-sm-6 ">
                <label class="control-label col-sm-4 ">证书编号：</label>
                <div class="col-sm-6">
                    <input type="text" class="form-control  " name="num" value="${data.num}">
                </div>
            </div>

            <div class="form-group col-sm-6">
                <label class="col-sm-4 control-label">发证日期：</label>
                <div class="col-sm-6">
                    <div class="input-group date form_date timeInput" style="">
                                                <span class="input-group-addon"><span
                                                        class="glyphicon glyphicon-calendar"></span></span>
                        <input class="form-control " type="text" name="startTime" value="<fmt:formatDate value="${data.startTime}" pattern="yyyy-MM-dd"/>" readonly>
                    </div>
                </div>
            </div>
            <div class="form-group col-sm-6">
                <label class="col-sm-4 control-label">有效期至：</label>
                <div class="col-sm-6">
                    <div class="input-group date form_date timeInput" style="">
                                                <span class="input-group-addon"><span
                                                        class="glyphicon glyphicon-calendar"></span></span>
                        <input class="form-control " type="text" name="endTime" value="<fmt:formatDate value="${data.endTime}" pattern="yyyy-MM-dd"/>" readonly>
                    </div>
                </div>
            </div>



            <div class="form-group col-sm-6 ">
                <label class="control-label col-sm-4 ">证书扫描件：</label>
                <div class="col-sm-6" id="div_imgBox">
                    <input type="file" class="fade" id="imgSrc" accept="image/*"     <c:if test="${data.imgSrc!=null}">data-src="downloadFileByPath?pathName=${data.imgSrc}"</c:if> >
                </div>
            </div>

            <div class="form-group col-sm-6">
                <div class="col-sm-6 col-sm-offset-4">
                    <button type="submit"
                            class="btn btn-default btn-success  "><span
                            class="glyphicon glyphicon-ok"></span>&nbsp;确&nbsp;定&nbsp;
                    </button>
                </div>
            </div>

        </form>
    </div>


</div>


<script>

    $.sysPlugin.initSelect2($("#grade"), {
        data: $.sysPlugin.enumeration.expertGrade,
        value: '${data.grade}'
    });
    $.sysPlugin.initSelect2($("#certificateTypeId"), {
        url: 'dictionary/publicOpen/certificateTypeOnlyLive',
        value: '${data.certificateTypeId}'
    });

    var imgObj = $('#imgSrc').imgupload({
        route: 'imgBase64upLoad/saveHeadImg',
    });


    <%--bootstrapValidator--%>
    $form=$("#form_data");
    $form.bootstrapValidator({
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            certificateTypeId: {
                validators: {
                    notEmpty: {
                        message: '不能为空！'
                    }
                }
            },
            name: {
                validators: {
                    notEmpty: {
                        message: '不能为空！'
                    }
                }
            },
            num: {
                validators: {
                    notEmpty: {
                        message: '不能为空！'
                    }
                }
            },
            grade: {
                validators: {
                    notEmpty: {
                        message: '不能为空！'
                    }
                }
            },
            startTime: {
                validators: {
                    notEmpty: {
                        message: '不能为空！'
                    }, callback: {
                        callback: function (value, validator) {
                            var var_endTime = $("#form_review").find("input[name='endTime']").val();
                            if (value != '' && var_endTime != '') {
                                if ((new Date(value)).getTime() > (new Date(var_endTime)).getTime()) {
                                    return {
                                        valid: false,
                                        message: '开始时间不能大于结束时间'
                                    }
                                }
                            }
                            return true;
                        }
                    }
                }
            },
            endTime: {
                validators: {
                    notEmpty: {
                        message: '不能为空！'
                    },
                    callback: {
                        callback: function (value, validator) {
                            var var_startTime = $("#form_review").find("input[name='startTime']").val();
                            if (value != '' && var_startTime != '') {
                                if ((new Date(value)).getTime() < (new Date(var_startTime)).getTime()) {
                                    return {
                                        valid: false,
                                        message: '结束时间不能小于开始时间'
                                    }
                                }
                            }
                            return true;
                        }
                    }
                }
            }
        }
    }).on('success.form.bv', function (e) {
        e.preventDefault();

        var src = $("#div_imgBox img").attr("src");
        if (src) {
            var i = src.indexOf("pathName=");
            if (i > -1) {
                src = src.substr(i + 9);
            }
        }
        var data = $(e.target).serializeObject();
        data.imgSrc = src;


        $.sysPlugin.superAjax({
            data: data,
            url: '${url}',
            operateType: '${operateType}',
            showSuccessAlert: true,
            showWarnAlert: false,
            successCall: function (data) {
                $.sysPlugin.successCallBack(data, {
                    modal: $("#modal_ajax"),
                });
                refreshTab($("#tab_expertCertificate"));
            },
            errorCall: function (data) {
                $.sysPlugin.errorCallBack(data, {
                    errorAddress: $("#div_error"),
                    form: $form
                })
            }
        });

    });


    $.sysPlugin.initDateTimeInput();
</script>
<%---证书script结束==========================================================--%>

